<%--
  Created by IntelliJ IDEA.
  User: 姚波
  Date: 2019/1/19
  Time: 13:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link type="text/css" rel="stylesheet" href="layuiadmin/layui/css/layui.css">
    <script src="layuiadmin/layui/layui.js"></script>
</head>
<body>

<div style="margin-bottom: 5px;">
    <!-- 示例-970 -->
    <ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-client="ca-pub-6111334333458862" data-ad-slot="3820120620"></ins>
</div>
<div class="layui-btn-group demoTable">
    <button class="layui-btn" data-type="getCheckData">导出数据</button>
    <button class="layui-btn" data-type="getCheckLength">删除选中</button>
    <button class="layui-btn" data-type="import">导入数据</button>
</div>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="collection">收藏</a>
</script>

<script type="text/html" id="barDemos">
    <a class="layui-btn layui-btn-xs" lay-event="shou">收获地址</a>
</script>

<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-xs" lay-event="vehicle">购物车</a>
</script>

<table class="layui-table" lay-data="{ url:'member',limit:5, id:'testReload', class:'testt', page:true,}" lay-filter="demo">
    <thead>
    <tr>
        <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
        <th lay-data="{field: 'uID', title: '会员ID', width: 80, fixed: 'left', unresize: true, sort: true}"></th>
        <th lay-data="{field: 'uAccount', title: '账号', width: 120}"></th>
        <th lay-data="{field:'uNickName', tille:'姓名', width:'50'}">姓名</th>
        <th lay-data="{field: 'uGender', title: '性别', width: 100,templet: function(res){
        if(res.uGender==0){
            return '男';
        }else{
         return '女';
        }
      }}"></th>
        <th lay-data="{field: 'uPhoneNumber', title: '手机号', width:100}"></th>
        <th lay-data="{field: 'uEmail', title: '邮箱', width: 80}"></th>
        <th lay-data="{field: 'uAddress', title: '地址'}"></th>
        <th lay-data="{field: 'uIntegral', title: '积分'}"></th>
        <th lay-data="{field: 'uRegdate', title: '注册时间', width: 120}"></th>
        <th lay-data="{field: 'uRegdate', title: '收获地址', width: 120,toolbar: '#barDemos',}"></th>
        <th lay-data="{field: 'uRegdate', title: '购物车', width: 120,toolbar: '#bar',}"></th>
        <th lay-data="{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}"></th>
    </tr>
    </thead>
</table>
<script>
    layui.use('table', function(){

        var table = layui.table;
        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });
        /*
        * 删除数据
        * */
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'del'){
                var con=confirm("真的要删除吗");
                if(con) {
                    $.ajax({
                        url: "deletes?u_id=" + data.uID,   //请求路径
                        datatype: "json",//返回的格式
                        type: "POST", //什么请求
                        success: function (data) { //请求成功以后

                        }
                    });
                }
            } else if(obj.event === 'edit'){
                parent.layer.open({   //打开一个弹出层
                    title: '修改信息',   //弹出层的标题
                    maxmin: true,
                    type: 2,
                    content: '../obtain?u_id='+data.uID,//要访问的地址
                    area: ['800px', '600px'],
                    end: function () { //表示弹出层关闭的时候的代码块
                        location.reload();
                    }
                });
            }else if(obj.event === 'shou'){
                parent.layer.open({   //打开一个弹出层
                    title: '收获地址',   //弹出层的标题
                    maxmin: true,
                    type: 2,
                    content: 'harves?u_id='+data.uID,//要访问的地址
                    area: ['800px', '600px'],
                    end: function () { //表示弹出层关闭的时候的代码块
                        location.reload();
                    }
                });
            }else if(obj.event === 'collection'){
             parent.layer.open({   //打开一个弹出层
                title: '收藏',   //弹出层的标题
                maxmin: true,
                type: 2,
                content: 'collection?u_id='+data.uID,//要访问的地址
                area: ['800px', '600px'],
                end: function () { //表示弹出层关闭的时候的代码块
                    location.reload();
                }
            });
        }else if(obj.event === 'vehicle'){
                parent.layer.open({   //打开一个弹出层
                    title: '购物车管理',   //弹出层的标题
                    maxmin: true,
                    type: 2,
                    content: 'shoppingCart?u_id='+data.uID,//要访问的地址
                    area: ['800px', '600px'],
                    end: function () { //表示弹出层关闭的时候的代码块
                        location.reload();
                    }
                });
            }
        });
        /**
         * 获取选中的所有数据id
         * @type {pe}
         */
        var $ = layui.$, active = {
            getCheckData: function(){ //获取选中数据
                var checkStatus = table.checkStatus('testReload')
                ,data=checkStatus.data;
                var objs=eval(data);
                if(objs.length != null && "" != objs.length){
                    layer.confirm('导出选中数据么', function (index){
                        var ids="";
                        for(var i=0;i<objs.length;i++){
                            if(i==0){
                                ids += objs[0].uID;
                            }else {
                                ids+= "," + objs[i].uID;
                            }
                        }
                        layer.closeAll('dialog'); //关闭信息框
                        window.location.href="/export?ids="+ids;
                    });

                }else {
                    layer.msg("未选中")
                }
            }
            ,getCheckLength: function(){ //获取选中数目
                var checkStatus = table.checkStatus('testReload')
                    ,data = checkStatus.data;
                var objs=eval(data);
                if(objs.length != null && "" != objs.length){
                    layer.confirm('删除数据', function (index){
                        var ids="";
                        for(var i=0;i<objs.length;i++){
                            if(i==0){
                                ids += objs[0].uID;
                            }else {
                                ids+= "," + objs[i].uID;
                            }
                        }
                        layer.closeAll('dialog'); //关闭信息框
                        window.location.href="/deleall?ids="+ids;
                    });

                }else {
                    layer.msg("未选中")
                }
            }
            ,import: function(){ //获取选中数目
                $.ajax({
                    url:"../imporse",   //请求路径
                    datatype:"json",//返回的格式
                    type:"POST", //什么请求
                    success:function (data) { //请求成功以后
                        //AJAX成功以后返回的
                        var obj = eval('(' + data + ')');
                        layer.msg(obj.message);
                        //延时500ms关闭窗口
                        setTimeout(function () {
                            parent.layer.close(index);
                        }, 500);
                    }
                });
            }
        };

    });

</script>

</body>
</html>
